package icu.sehnen.product.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import icu.sehnen.product.entity.MyPage;
import icu.sehnen.product.entity.Product;
import icu.sehnen.product.mapper.ProductMapper;
import icu.sehnen.product.service.IProductService;
import io.swagger.models.auth.In;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author icu.sehnen
 * @since 2021-04-26
 */
@Service
public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> implements IProductService {
    @Autowired
    ProductMapper productMapper;
    @Override
    public Product getProductById(Long id) {
       return productMapper.getProductById(id);
    }

    @Override
    public IPage<Product> findAll(MyPage myPage, Product product) {
//        QueryWrapper<Product> queryWrapper = new QueryWrapper();
//        queryWrapper.like(!StringUtils.isBlank(product.getName()),"name",product.getName());
//        queryWrapper.between(product.getCreateTime()!=null,"create_time",product.getCreateTime(),getNow());
        return productMapper.findAll(myPage,product);
    }
    private Date getNow() {
        Date date = new Date();
        SimpleDateFormat format0 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String time = format0.format(date);
        Date time1= null;
        try {
            time1 = format0.parse(time);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return time1;
    }
}
